package com.examination.exam.utils;

import com.examination.domain.exam.entity.ExamPaper;
import com.examination.domain.exam.entity.Examination;
import com.examination.domain.exam.entity.Question;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ExamPaperUtil {
    public static ExamPaper getExamPaper(String userId, String examId, Examination examination) {
        ExamPaper examPaper = new ExamPaper();
        examPaper.setUserID(userId);
        examPaper.setEaminationID(examId);
        examPaper.setUserJoinTime(MetaDataUtil.getTimeStr());
        examPaper.setUserFinishTime(null);
        List<Question> questionList = examination.getQuestionList();
        List<Integer> indexsList = new ArrayList<>();
        for (int i = 0; i < questionList.size(); i++) {
            indexsList.add(i);
        }

        //题目乱序
        if (examination.getQuestionOrder())
            Collections.shuffle(indexsList);

        examPaper.setQuestionIndexList(indexsList);

        List<List<String>> answersList = new ArrayList<>();
        examPaper.setAnswersList(answersList);
        return examPaper;
    }
}
